import { _decorator, Component, find, Label, Node } from 'cc';
const { ccclass, property } = _decorator;
import goldManager from '../managers/goldManager';
import HealthUp from '../managers/healthData/healthUp';
import GlobalEvent from '../Global/GlobalEvent';
import atkUp from '../managers/atkData/atkUp';
import speedUp from '../managers/speedData/speedUp';
@ccclass('buyHealthBtn')
export class buyHealthBtn extends Component {
    @property(Node)
    private healthBtn: Node = null;
    @property(Node)
    private healthLv: Node = null;
    @property(Node)
    private LvScore: Node = null;
    @property(Node)
    private goldView: Node = null;
    @property(Node)
    @property(Node)
    private btn_Add_health: Node = null;
    @property(Node)
    private btn_Add_health2: Node = null;


    private bool = false;

    private getHealth;
    private getGoldBtn;
    private goldhealth;
    private goldGetLv;

    start() {
        GlobalEvent.on('getHealthBoolean', (e) => {
            this.healthBtn.active = e;
        })
        const healthup = HealthUp.getInstance();
        const goldmanager = goldManager.getInstance();
        this.getGoldBtn = healthup.addhealth();
        this.getHealth = goldmanager.getGold();

        if (this.goldView) {
            const label = this.goldView.getComponent(Label);
            label.string = `金币:${this.getHealth}`;
        }

    }

    update(deltaTime: number) {

    }
    //购买生命值按钮
    healthBtnFun() {
        const goldmanager = goldManager.getInstance();
        const healthup = HealthUp.getInstance();
        const atkup = atkUp.getInstance();
        const goldGetLv = healthup.getlv();
        const goldhealth = healthup.addhealth();
        this.getGoldBtn = healthup.addgold();
        goldmanager.btnMinuGold(this.getGoldBtn);
        healthup.getHealthbool();
        atkup.getAtkbool();

        const speedup = speedUp.getInstance();
        speedup.getSpeedBool();
        //点击购买 增加lv
        healthup.upLv();

        //获取购买生命值的金币
        //获取购买生命值的金币
        this.goldGetLv = goldGetLv;
        this.goldhealth = goldhealth;

        this.renderGold();

    }


    

    //渲染生命值
    renderGold() {
        const goldmanager = goldManager.getInstance();
        let healthup = HealthUp.getInstance();
        const goldGetLv = healthup.getlv();
        const goldhealth = healthup.addhealth();
        
        this.getHealth = goldmanager.getGold();
        this.getGoldBtn = healthup.addgold();


        //获取购买生命值的金币
        this.goldGetLv = goldGetLv;
        this.goldhealth = goldhealth;

        const goldview = this.goldView.getComponent(Label);
        goldview.string = `金币:${this.getHealth}`;

        const healthLv = this.healthLv.getComponent(Label);
        healthLv.string = `Lv.${this.goldGetLv}`;

        const LvScore = this.LvScore.getComponent(Label);
        LvScore.string = `+${this.goldhealth}`;

        const btn_Add_health = this.btn_Add_health.getComponent(Label);
        btn_Add_health.string = `${this.getGoldBtn}`;

        const btn_Add_health2 = this.btn_Add_health2.getComponent(Label);
        btn_Add_health2.string = `${this.getGoldBtn}`;


    }
}

